package com.shujia.java.day1;

public class Demo2 {
    public static void main(String[] args) {

        /*
         *运算符
         * + - * / %
         */

        int a = 10;
        int b = 3;

        System.out.println(a + b);
        System.out.println(a - b);
        System.out.println(a * b);
        System.out.println(a / b);//整除
        System.out.println(a % b);//取余


        System.out.println((double) a / b);//将整数转换成小数


        //自增  自减
        int i = 10;
        i++;//自增  相当于 i = i + 1;
        System.out.println(i);
        i--;//自减   相当于 i = i - 1;
        System.out.println(i);

        System.out.println("=================================");

        //i++  先运算在自增  ++i 先自增再运算
//        int j = i++;
//        System.out.println(i);
//        System.out.println(j);
        int k = ++i;
        System.out.println(i);
        System.out.println(k);

        //字符串拼接   如果一个表达式里面有String类型 最后返回一个String类型的结果
        String s = "hello" + "word" + (23 + 12);

        System.out.println(s);
        System.out.println("=================================");

        int c = 10;

        c += 2;// c = c + 2
        System.out.println(c);


        int l, n, m;
        l = n = m = 4;

        System.out.println(l);
        System.out.println(n);
        System.out.println(m);


        //java 整数默认类型是int   通过算术运算符计算之后类型也是int类型
        short s1 = 30000;
        short s2 = (short) (s1 + s1);
        System.out.println(s2);
        s1 += 30000;
        System.out.println(s1);


        /**
         * 比较运算符
         * ==  !=  <  >   >=  <=
         *
         */

        int y = 10;
        int o = 12;

        boolean b1 = y == o;

        System.out.println(b1);
        System.out.println(y != o);
        System.out.println(y > o);
        System.out.println(y < o);
        System.out.println(y >= o);
        System.out.println(y <= o);

        System.out.println("=========================");

        /**
         * 逻辑运算符
         * &  两边都为true  返回true
         * |  有一边为true  返回true
         * !   取反
         *
         * &&  如果左边为false  不再判断右边，直接返回false
         * ||  如果左边为ftrue  不再判断右边，直接返回true
         */


        boolean b2 = true;
        boolean b3 = false;

        System.out.println(b2 & b3);
        System.out.println(b2 | b3);
        System.out.println(!b3);
        System.out.println(b2 && b3);//效率比& 高
        System.out.println(b2 || b3);


    }
}
